<?php
/**
 * @Author: Xu Liu email:2867557054@qq.com
 * @Date:   2016-12-15 13:31:33
 * @Last Modified by:   Xu Liu
 * @Last Modified time: 2018-04-21 19:14:21
 */
if (!defined('IN_DISCUZ')) {
    exit('Access Denid');
}
class table_jamesonread_update extends discuz_table
{
    public function __construct()
    {
        $this->_table = 'jamesonread_update';
        $this->_pk    = 'book_id';
        parent::__construct();
    }
    public function add($data)
    {
    	$has = DB::result_first('SELECT count(book_id) FROM %t WHERE book_id=%d LIMIT %d',array($this->_table,$data['book_id'],1));
    	if(!$has){
    		$this->insert($data);
    	}else{
    		$this->update($data['book_id'],$data);
    	}
    	return true;
    }
    function fetch_update($size){
    	$data = DB::fetch_all('SELECT u.book_id,u.tid,u.pid,u.subject,b.book_name,b.status,b.category_id,b.parent_id,b.image,b.author,b.plan FROM %t as u inner join %t as b on u.book_id=b.book_id where b.status > %d  ORDER BY u.addtime DESC LIMIT %d,%d',array($this->_table,'jamesonread_books',0,0,$size),'book_id');
        if($data){
            return array_values($data);
        }
        return $data;
    }
}